package com.gen.utils.ngen;

import com.google.common.collect.Lists;

import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

public class WordGen {
    public static String [] vowel = {"a","e","i/y","o","u"};
    public static String [] vowelGroup = {"ar","er","ir","or","ur","are","ere","ire","ore","ure","ai/ay","air","al","au/aw","ea","ear","ee","eer","ei/ey","eu/ew","ie","oa","oar/oor","oi/oy","oo","ou/ow","our","ui"};
    public static String[] consonant = {"b","c","d","f","g","h","j","k","l","m","n","p","q","r","s","t","v","w-","x","y-","z"};
    public static String[] consonGroup = {"ch","-ck","-dge","dr-","-ds","gh","gu-","kn-","-mn","-ng","ph","qu-","sh","-tch","th","tr-","-ts","wh-","wr-"};


    private static  String getStart(){
        List allconsonant = Lists.newArrayList(consonant);
        allconsonant.addAll(Lists.newArrayList(consonGroup));
        allconsonant = (List) allconsonant.stream().filter(v->!v.toString().startsWith("-")).collect(Collectors.toList());
        return (String)allconsonant.get(new Random().nextInt(allconsonant.size())).toString().replaceAll("\\-","");
    }
    private static String getMiddle(){
        List allvowel = Lists.newArrayList(vowel);
        allvowel.addAll(Lists.newArrayList(vowelGroup));

        String vowel = allvowel.get(new Random().nextInt(allvowel.size())).toString();
        if(vowel.contains("/")){
            String[] vos =   vowel.split("/");
            vowel = vos[new Random().nextInt(vos.length)];
        }
        return vowel;
    }
    private static String getEnd(){
        List allconsonant = Lists.newArrayList(consonant);
        allconsonant.addAll(Lists.newArrayList(consonGroup));
        allconsonant = (List) allconsonant.stream().filter(v->v.toString().startsWith("-")).collect(Collectors.toList());
        return (String)allconsonant.get(new Random().nextInt(allconsonant.size())).toString().replaceAll("\\-","");
    }
    public static String genWord(){
        int len = 5;
        String word = "";
        while (word.length() < len){
            word += getStart()+getMiddle();
        }
        if(new Random().nextInt(2) == 1){
            word += getEnd();
        }
        return word;
    }
    public static void main(String[] arg){

        for(int i = 0 ;i<100;i++){
            System.out.println(genWord());;

        }
    }



}
